package agency.tango.materialintro.slice;

import agency.tango.materialintro.MaterialIntro;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Button;
import ohos.agp.components.Image;
import ohos.agp.utils.Color;
import agency.tango.materialintroscreen.utils.LogUtil;

import agency.tango.materialintro.ResourceTable;
import agency.tango.materialintroscreen.utils.ElementUtil;

/**
 * @ProjectName: material-intro-screen-master
 * @Package: agency.tango.materialintro.slice
 * @ClassName: MainAbilitySlice
 * @Description: 首页，用于跳转pageslider显示界面
 * @CreateDate: 2021/4/12 14:34
 * @UpdateDate: 2021/4/12 14:34
 * @UpdateRemark: 暂无
 * @Version: 1.0
 */
public class MainAbilitySlice extends AbilitySlice {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        MaterialIntro.setIsFirstOpen(false);
        super.setUIContent(ResourceTable.Layout_ability_main);
    }

    @Override
    protected void onActive() {
        super.onActive();
        initView();
    }

    private void initView() {
        Button button =
                (Button) findComponentById(ResourceTable.Id_btn_launch_activity);
        button.setClickedListener(component -> {
            Intent secondIntent = new Intent();
            // 指定待启动FA的bundleName和abilityName
            Operation operation = new Intent.OperationBuilder()
                    .withDeviceId("")
                    .withBundleName("agency.tango.materialintro")
                    .withAbilityName("agency.tango.materialintro.IntroAbility")
                    .build();
            secondIntent.setOperation(operation);
            startAbility(secondIntent); // 通过AbilitySlice的startAbility
            // 接口实现启动另一个页面
        });
        getWindow().setStatusBarColor(new Color(ElementUtil.getColor(getContext(),
                ResourceTable.Color_statusBar_color)).getValue());

        Button btJump =
                (Button) findComponentById(ResourceTable.Id_btn_show_parallax_demo);
        btJump.setClickedListener(component -> {
            try {
                Intent secondIntent = new Intent();
                // 指定待启动FA的bundleName和abilityName
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName("agency.tango.materialintro")
                        .withAbilityName("agency.tango.materialintro.ShowDemoAbility")
                        .build();
                secondIntent.setOperation(operation);
                startAbility(secondIntent); // 通过AbilitySlice的startAbility
            } catch (Exception e) {
                LogUtil.info("MainAbilitySlice", e.toString());
            }
            // 接口实现启动另一个页面
        });

    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

}
